home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / ExtUtils / Miniperl.pm < prev    next >
Encoding:
Perl POD Document  |  1999-12-28  |  3.1 KB  |  152 lines

  1.  
  2.  
  3. package ExtUtils::Miniperl;
  4. require Exporter;
  5. @ISA = qw(Exporter);
  6. @EXPORT = qw(&writemain);
  7.  
  8. $head= <<'EOF!HEAD';
  9. /*
  10.  * "The Road goes ever on and on, down from the door where it began."
  11.  */
  12.  
  13. extern "C" {
  14.  
  15.  
  16. }
  17.  
  18. static void xs_init _((void));
  19. static PerlInterpreter *my_perl;
  20.  
  21. int
  22. main(int argc, char **argv, char **env)
  23. main(argc, argv, env)
  24. int argc;
  25. char **argv;
  26. char **env;
  27. {
  28.     int exitstatus;
  29.  
  30.     PERL_SYS_INIT(&argc,&argv);
  31.  
  32.     perl_init_i18nl10n(1);
  33.  
  34.     if (!do_undump) {
  35.     my_perl = perl_alloc();
  36.     if (!my_perl)
  37.         exit(1);
  38.     perl_construct( my_perl );
  39.     perl_destruct_level = 0;
  40.     }
  41.  
  42.     exitstatus = perl_parse( my_perl, xs_init, argc, argv, (char **) NULL );
  43.     if (!exitstatus) {
  44.     exitstatus = perl_run( my_perl );
  45.     }
  46.  
  47.     perl_destruct( my_perl );
  48.     perl_free( my_perl );
  49.  
  50.     PERL_SYS_TERM();
  51.  
  52.     exit( exitstatus );
  53. }
  54.  
  55. /* Register any extra external extensions */
  56.  
  57. EOF!HEAD
  58. $tail=<<'EOF!TAIL';
  59.  
  60. static void
  61. xs_init()
  62. {
  63. }
  64. EOF!TAIL
  65.  
  66. sub writemain{
  67.     my(@exts) = @_;
  68.  
  69.     my($pname);
  70.     my($dl) = canon('/','DynaLoader');
  71.     print $head;
  72.  
  73.     foreach $_ (@exts){
  74.     my($pname) = canon('/', $_);
  75.     my($mname, $cname);
  76.     ($mname = $pname) =~ s!/!::!g;
  77.     ($cname = $pname) =~ s!/!__!g;
  78.     print "EXTERN_C void boot_${cname} _((CV* cv));\n";
  79.     }
  80.  
  81.     my ($tail1,$tail2) = ( $tail =~ /\A(.*\n)(\s*\}.*)\Z/s );
  82.     print $tail1;
  83.  
  84.     print "\tchar *file = __FILE__;\n";
  85.     print "\tdXSUB_SYS;\n" if $] > 5.002;
  86.  
  87.     foreach $_ (@exts){
  88.     my($pname) = canon('/', $_);
  89.     my($mname, $cname, $ccode);
  90.     ($mname = $pname) =~ s!/!::!g;
  91.     ($cname = $pname) =~ s!/!__!g;
  92.     print "\t{\n";
  93.     if ($pname eq $dl){
  94.         $ccode = "\t/* DynaLoader is a special case */\n
  95. \tnewXS(\"${mname}::boot_${cname}\", boot_${cname}, file);\n";
  96.         print $ccode unless $SEEN{$ccode}++;
  97.     } else {
  98.         $ccode = "\tnewXS(\"${mname}::bootstrap\", boot_${cname}, file);\n";
  99.         print $ccode unless $SEEN{$ccode}++;
  100.     }
  101.     print "\t}\n";
  102.     }
  103.     print $tail2;
  104. }
  105.  
  106. sub canon{
  107.     my($as, @ext) = @_;
  108.     foreach(@ext){
  109.         next if s!::!/!g;
  110.         s:^(lib|ext)/(auto/)?::;
  111.         s:/\w+\.\w+$::;
  112.     }
  113.     grep(s:/:$as:, @ext) if ($as ne '/');
  114.     @ext;
  115. }
  116.  
  117. 1;
  118. __END__
  119.  
  120. =head1 NAME
  121.  
  122. ExtUtils::Miniperl, writemain - write the C code for perlmain.c
  123.  
  124. =head1 SYNOPSIS
  125.  
  126. C<use ExtUtils::Miniperl;>
  127.  
  128. C<writemain(@directories);>
  129.  
  130. =head1 DESCRIPTION
  131.  
  132. This whole module is written when perl itself is built from a script
  133. called minimod.PL. In case you want to patch it, please patch
  134. minimod.PL in the perl distribution instead.
  135.  
  136. writemain() takes an argument list of directories containing archive
  137. libraries that relate to perl modules and should be linked into a new
  138. perl binary. It writes to STDOUT a corresponding perlmain.c file that
  139. is a plain C file containing all the bootstrap code to make the
  140. modules associated with the libraries available from within perl.
  141.  
  142. The typical usage is from within a Makefile generated by
  143. ExtUtils::MakeMaker. So under normal circumstances you won't have to
  144. deal with this module directly.
  145.  
  146. =head1 SEE ALSO
  147.  
  148. L<ExtUtils::MakeMaker>
  149.  
  150. =cut
  151.  
  152.